package com.lion.tag.tab;

import java.io.IOException;

import javax.servlet.jsp.JspException;

import com.lion.tag.LionBaseTag;
import com.lion.tag.util.AppendUtil;

public class Tab extends LionBaseTag {
	private static final long serialVersionUID = 6472006641106028814L;
	private String tabWidth;// 选项卡宽度
	private String tabHeight;// 选项卡高度
	private String tabPosition;// 选项卡方向（top、bottom、left、right）
	private String tools;
	private String fit;
	private boolean border = true;//外边框

	/**
	 *实现选项卡
	 */
	@Override
	public int doStartTag() throws JspException {
		StringBuilder sb = new StringBuilder(200);
		sb.append("<div ");
		sb = AppendUtil.addAttribute(sb, "id", id);
		sb = AppendUtil.addAttribute(sb, "class", "easyui-tabs");
		sb = AppendUtil.addAttribute(sb, "style", style);
		int hasData = 0;
		hasData = AppendUtil.appendOptionData(sb, hasData, "border", border+"",false);
		if (tabWidth != null && !tabWidth.equals("")) {
			hasData = AppendUtil.appendOptionData(sb, hasData, "tabWidth", tabWidth,false);
		}
		if (tabHeight != null && !tabHeight.equals("")) {
			hasData = AppendUtil.appendOptionData(sb, hasData, "tabHeight", tabHeight,false);
		}
		if (fit != null && !fit.equals("")) {
			hasData = AppendUtil.appendOptionData(sb, hasData, "fit", fit,false);
		}
		if (tabPosition != null && !tabPosition.equals("")) {
			hasData = AppendUtil.appendOptionData(sb, hasData, "tabPosition", tabPosition,true);
		}
		if (tools != null && !tools.equals("")) {
			if (tools.charAt(0) != '#') {
				tools = "#" + tools;
			}
			hasData = AppendUtil.appendOptionData(sb, hasData, "tools", tools,true);
		}
		if (hasData == 1) {
			sb.append("\">");
		} else {
			sb.append(">");
		}
		try {
			pageContext.getOut().write(sb.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_BODY_INCLUDE;// 表示标签之间的内容被正常执行
	}

	@Override
	/**  
	 *  doEndTag：当JSP容器遇到自定义标签的结束标志，就会调用doEndTag()方法。doEndTag()方法也返回一个整数值，用来决定程序后续流程。  
	 *  A.Tag.SKIP_PAGE：表示立刻停止执行网页，网页上未处理的静态内容和JSP程序均被忽略任何已有的输出内容立刻返回到客户的浏览器上。  
	 *  B.Tag.EVAL_PAGE：表示按照正常的流程继续执行JSP网页  
	 */
	public int doEndTag() throws JspException {
		try {
			pageContext.getOut().write("</div>");
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}

	/**
	 * @return the tabWidth
	 */
	public String getTabWidth() {
		return tabWidth;
	}

	/**
	 * @param tabWidth
	 *            the tabWidth to set
	 */
	public void setTabWidth(String tabWidth) {
		this.tabWidth = tabWidth;
	}

	/**
	 * @return the tabHeight
	 */
	public String getTabHeight() {
		return tabHeight;
	}

	/**
	 * @param tabHeight
	 *            the tabHeight to set
	 */
	public void setTabHeight(String tabHeight) {
		this.tabHeight = tabHeight;
	}

	/**
	 * @return the tabPosition
	 */
	public String getTabPosition() {
		return tabPosition;
	}

	/**
	 * @param tabPosition
	 *            the tabPosition to set
	 */
	public void setTabPosition(String tabPosition) {
		this.tabPosition = tabPosition;
	}

	/**
	 * @return the tools
	 */
	public String getTools() {
		return tools;
	}

	/**
	 * @param tools
	 *            the tools to set
	 */
	public void setTools(String tools) {
		this.tools = tools;
	}

	/**
	 * @return the fit
	 */
	public String getFit() {
		return fit;
	}

	/**
	 * @param fit
	 *            the fit to set
	 */
	public void setFit(String fit) {
		this.fit = fit;
	}

	public boolean isBorder() {
		return border;
	}

	public void setBorder(boolean border) {
		this.border = border;
	}

}
